﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ClikUrlTest</title>
    <!--https://coachingfootballsecrets.googlecode.com/svn/GetWeather/trunk/TestClikUrl.htm?url=www.coachingfootballsecrets.com-->
</head>
<body>
<div id="out"></div>
<script>
function _unesc(s) {
  return window.decodeURIComponent ? decodeURIComponent(s) : unescape(s);
}
function _args() {
  var args = new Object();
  var query = document.location.search.substring(1);
  var pairs = query.split('&');
  for ( var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if ( pos == -1 ) continue;
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    value = value.replace(/\+/g, ' ');
    args[argname] = _unesc(value);
  }
  return args;
}

var args = _args();
var msg = args['msg'];
var url = args['url'] || args['adurl'];

if (url) {
  url = _unesc(url);
  msg = (parseInt(msg) == 1) ? true : false;

  // Get list of URL parameters passed in.
  var params = [];
  for (var n in args) {
    params.push(n + '=' + args[n]);
  }

  var regexp = new RegExp('^http[s]?://.*');
  if (url.match(regexp)) {
    var str = [
      '*** Click Received ***',
      '',
      'Destination URL:',
      url,
      '',
      'Parameters:',
      params.join('\n')
    ];

    if (msg) {
      if (window.confirm(str.join('\n'))) {
        window.location.replace(url);
      } else {
        window.history.back();
      }
    } else {
      window.location.replace(url);
    }
  } else {
    document.write([
      '<h2>Bad destination URL</h2>',
      url
    ].join(''));
  }
}
</script>

</body>
</html>
